package com.passport_main.controller;

import com.common.result.JsonResult;
import com.passport_main.pojo.dto.LoginDTO;
import com.passport_main.service.PassportService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
@Slf4j
@Api("PassportController")
@Validated
@RestController
@RequestMapping("v1/passport")
public class PassportController {
    @Autowired
    PassportService passportService;

    @ApiOperation("用户登录")
    @PostMapping("login")
    public JsonResult login( @RequestBody LoginDTO loginDTO, HttpServletRequest httpServletRequest){

        log.info("controller:开始处理用户登录");
        log.info("controller:用户上传dto: {}", loginDTO);
        //拿到客户端IP地址
        String addr =httpServletRequest.getRemoteAddr();
        String userAgent=httpServletRequest.getHeader("User-Agent");


        JsonResult jsonResult= passportService.login(loginDTO,httpServletRequest,addr,userAgent);
        log.info("controller:用户登录结束:{}",jsonResult);
        return jsonResult;
    }
}
